// pages/activity/index.js
import api from '../../utils/api.js';
import message from '../../utils/message.js';

Page({

    /**
     * 页面的初始数据
     */
    data: {
        userId:'',
        username:'张三',
        activityList:[],
        static_url:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

        console.log(options);
        if(options.id){
            console.log(options)
        }

        //定义分享到朋友圈接口  ，正式上线后才可以
        wx.showShareMenu({
            withShareTicket:true,
            menus: ["shareAppMessage" ,"shareTimeLine"],
        })

        var app = getApp();

        this.setData({
            static_url: app.globalData.static_url
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

        

    },


    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

        wx.getShareInfo({
          shareTicket: 'shareTicket',
        })

        this.getActivityList();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function (res) {
        //分享好友

        if( res.from=='button' ){
            console.log(res.target , res);
        }

        var options = {
            title: '分享标题',
            path: '/pages/activity/detail?id=100',
            imageUrl: '../../images/icon-order-tab.png'
        }


        //options.title= this.data.username+"邀请你参与"+"登录注册送好礼活动";
        //options.path = '/pages/index/index?userid='+this.data.userId;
        return options;

    },
    onShareTimeline:function(){
        return {
            title: '测试小程序分享至朋友圈',
            path: '../test/test',
            imageUrl:'https://www.hujingx.com/broad/Public/images/banner.jpg'
        }
    },
    getActivityList:function () {
        var me = this;
        message.show_loading();
        api.getActivityList({} , function( response ){
            message.hide_loading();

            if( response.status==1 ){
                me.setData({
                    activityList: response.data,
                    has_load:true
                })
            }else{
                message.show_error( response.message )
            }
        })
    }
})